const {Kafka} = require('kafkajs')

const kafka = new Kafka({
    clientId: 'my-app',
    brokers: ['kafka1:9092', 'kafka2:9092'],
})
const consumer = kafka.consumer({groupId: 'test-group'})

await consumer.connect()
await consumer.subscribe({topic: 'test-topic', fromBeginning: true})

await consumer.run({
    eachMessage: async ({topic, partition, message}) => {
        console.log({
            key: message.key.toString(),
            value: message.value.toString(),
        })
    },
})
